<template>
  <d2-container>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <div class="d2-breadcrumb">
        <el-breadcrumb-item>编辑员工</el-breadcrumb-item>
      </div>
    </el-breadcrumb>
    <el-form label-width="150px" :model="query" :rules="rules" ref="add">
      <el-form-item label="角色" prop="roleId">
        <el-select
          v-model="query.roleId"
          placeholder="请选择"
          style="width: 240px"
        >
          <el-option
            :label="item.roleName"
            :value="item.roleId"
            v-for="(item, index) in roleList"
            :key="index"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="员工昵称" prop="nickName">
        <el-input v-model="query.nickName" style="width: 240px"></el-input>
      </el-form-item>
      <el-form-item label="联系方式" prop="phonenumber">
        <el-input v-model="query.phonenumber" style="width: 240px"></el-input>
      </el-form-item>
      <el-form-item label="员工登录账号" prop="userName">
        <el-input v-model="query.userName" style="width: 240px"></el-input>
      </el-form-item>
      <el-form-item label="员工登录密码" prop="password">
        <el-input v-model="query.password" style="width: 240px"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="add">保存</el-button>
      </el-form-item>
    </el-form>
  </d2-container>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      id: this.$route.params.id,
      query: {
        userType: "00",
      },
      rules: {},
      roleList: [],
    };
  },
  methods: {
    add() {
      this.$refs["add"].validate((valid) => {
        if (valid) {
          let params = {
            ...this.query,
          };
          console.log("提交内容：", params);
          this.$axios.post("/sysUser/update", params).then((result) => {
            console.log("响应", result);
            if (result.data == 1) {
              this.$message.success("操作成功");
              this.$router.push("/systemAdmin");
              this.$refs["add"].resetFields();
            } else {
              this.$message.error(result.data.msg);
            }
          });
        } else {
          return false;
        }
      });
    },
    getInfo() {
      this.$axios
        .post("/sysUser/getUserInfo", { userId: this.id })
        .then((result) => {
          if (result) {
            this.query = {
              ...result.data,
              ...this.query,
            };
          } else {
            this.$message.error(result.data.msg);
          }
        });
    },
  },
  mounted() {
    this.getInfo();
    let params = {
      pageNum: 1,
      pageSize: 9999999,
      status: 0,
    };

    this.$axios.post("/sysRole/list", params).then((result) => {
      if (result) {
        this.roleList = result.data.list;
      } else {
        this.$message.error(result.data.msg);
      }
    });
  },
};
</script>

<style scoped lang="scss">
.item-box {
  position: relative;
  width: 30%;
  .item-delete {
    position: absolute;
    right: 80px;
    top: -45px;
  }
}
.card-box {
  display: flex;
  flex-wrap: wrap;
}
</style>
